package com.zgf.easy.proxy.demo;

import com.zgf.easy.proxy.EasyProxy;
import com.zgf.easy.proxy.demo.extend.order.OrderExtendApi;
import com.zgf.easy.proxy.demo.extend.order.mode.OrderReq;
import com.zgf.easy.proxy.demo.extend.order.mode.OrderRes;
import com.zgf.easy.proxy.demo.extend.user.UserExtendApi;
import com.zgf.easy.proxy.demo.extend.user.mode.UserReq;
import com.zgf.easy.proxy.demo.extend.user.mode.UserRes;
import com.zgf.easy.proxy.demo.impla.BizModuleA;
import com.zgf.easy.proxy.demo.implb.BizModuleB;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;

import javax.annotation.PostConstruct;
import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
@Slf4j
@SpringBootApplication
public class EasyProxyDemoApplication {

	public static void main(String[] args) {
		SpringApplication.run(EasyProxyDemoApplication.class, args);
	}

	/**
	 * @param context 透传到接口实现里面 非必选
	 * @return
	 */
	@Bean
	public EasyProxy easyProxy(@Autowired ApplicationContext context) throws InstantiationException, IllegalAccessException {
		EasyProxy proxy = new EasyProxy(context, threadPoolExecutor());
		proxy.scanPackages(BizModuleA.class, BizModuleB.class);
		return proxy;
	}

	@Bean
	public ThreadPoolExecutor threadPoolExecutor() {
		ThreadPoolExecutor executor = new ThreadPoolExecutor(100, 200, 1, TimeUnit.DAYS, new LinkedBlockingDeque<>(100));
		return executor;
	}

}
